package com.yq.comm.service.impl;

import com.yq.comm.command.InitContextCommand;
import com.yq.comm.command.impl.FileUploadPathInitCommand;
import com.yq.comm.invoker.InitContextCommandInvoker;
import com.yq.comm.service.InitContextService;
import org.springframework.stereotype.Service;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yq on 16-8-14.
 */
@Service
public class InitContextServiceImpl implements InitContextService {

    public void doInitContext() {
        List<InitContextCommand> commandList = getCommandList();
        InitContextCommandInvoker initContextCommandInvoker = new InitContextCommandInvoker();
        for (InitContextCommand initContextCommand : commandList) {
            initContextCommandInvoker.executeCommand(initContextCommand);
        }
    }

    /**
     * bean被创建后，执行此方法初始化环境
     * */
    @PostConstruct
    public void invokeDoInitContext(){
        doInitContext();
    }

    private List getCommandList() {
        List<InitContextCommand> commandList = new ArrayList<InitContextCommand>();
        InitContextCommand fileUploadPathInitCommand = new FileUploadPathInitCommand();
        commandList.add(fileUploadPathInitCommand);
        return commandList;
    }
}
